﻿@using System.Text
@using KRM.Core
@model KRM.Core.tblRDMQuestionnaire
@{
    ViewBag.Title = "AddRdm";
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
    var db = new KRMEntities();
    var brief = db.vWebBriefOrderItemDetails.FirstOrDefault(a => a.OrderItemID == Model.OrderItemID);
    var orderItem = db.tblOrderItems.Find(Model.OrderItemID);
    var futherDescription = new StringBuilder();
    if (Model.IsFAC51CheckList == true)
    {
        if (Model.IsNewQuestionnaireForm())
        {
            foreach (var answer in Model.RdmQuestionnaireAnswers.OrderByDescending(p => p.Id))
            {
                futherDescription = futherDescription.AppendLine(answer.Question.ShortDescription + " : " + answer.Comment);
            }
            futherDescription = futherDescription.AppendLine("OTHER: " + (Model.OtherComments ?? ""));
        }
        else
        {
            futherDescription = futherDescription.AppendLine("CHECKED PARTS : " + (Model.CheckedAllPartsComments ?? " "))
            .AppendLine("DAILY EXCEPTION REPORT: " + (Model.CheckedDailyExceptionReportComment ?? ""))
            .AppendLine("LABELLED: " + (Model.LabelledCorrectlyComments ?? ""))
            .AppendLine("PACKING SHEET: " + (Model.PackersName ?? ""))
            .AppendLine("PHOTOS: " + (Model.CustomerPhotosComments ?? "") + "," +
            (Model.DriverPhotosComments ?? ""))
            .AppendLine("OTHER: " + (Model.OtherComments ?? ""));
        }
    }
    else
    {
        futherDescription = futherDescription.AppendLine("CHECKED PARTS : " + (Model.CheckedAllPartsComments ?? " "))
            .AppendLine("BOX CONDITION : " + (Model.AskedConditionOfTheBoxComments ?? ""))
            .AppendLine("PHOTOS: " + (Model.PhotosOrPictureComments ?? ""))
            .AppendLine("OTHER: " + (Model.OtherComments ?? ""));
    }
}

<div id="addPhoto" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <form action="/rdm/addphoto" id="fr-AddPhoto" method="POST" enctype="multipart/form-data" class="margin0">
        <input type="hidden" name="QuestionnaireID" value="@Model.ID" />

        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h5 id="myModalLabel">Add image</h5>
        </div>
        <div class="modal-body">
            <div class="row-fluid">
                <div class="span3">Image</div>
                <div class="span9">
                    <input type="file" name="image" required="required" accept="image/*" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Description</div>
                <div class="span9">
                    <textarea name="Description" class="input-block-level"></textarea>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <input type="submit" class="btn btn-primary" value="Upload">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
    </form>
</div>
<div id="addDocument" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <form action="/rdm/addDocument" id="fr-AddDocument" method="POST" enctype="multipart/form-data" class="margin0">
        <input type="hidden" name="questionnaireid" value="@Model.ID" />
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h5>Add document</h5>
        </div>
        <div class="modal-body">
            <div class="row-fluid">
                <div class="span3">Image</div>
                <div class="span9">
                    <input type="file" name="file" required="required" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Name</div>
                <div class="span9">
                    <input type="text" name="Name" class="input-block-level" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Description</div>
                <div class="span9">
                    <textarea name="Description" class="input-block-level"></textarea>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <input type="submit" class="btn btn-primary" value="Upload">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
    </form>
</div>
@Html.Partial("Partial/Rdm/_EditPhoto")
@Html.Partial("Partial/Rdm/_EditDocument")
<div style="padding: 10px">
    @Html.Partial("Partial/_MessageResult")
    <input type="hidden" id="OrderItemID" value="@Model.OrderItemID"/>
    <div class="row-fluid">
        <div class="span3">
            <div class="span3">OrderRef</div>
            <div class="span9">
                <input type="text" class="input-block-level" value="@brief.OrderRef" disabled="disabled" />
            </div>
        </div>
        <div class="span5">
            <div class="span3">OrderItems</div>
            <div class="span9">
                <input type="text" class="input-block-level" value="@Model.Order_Items" disabled="disabled" />
                @if (orderItem.Order.OrderItems.Any(p => p.ProductID == tblCompanyVariable.AssemblyProductID))
                {
                    <span style="color: red; font-weight: bold; font-size: 14px">NOTE: ORDER HAS ASSEMBLE SERVICE</span>
                }
            </div>
        </div>
        <div class="span4">
            <div class="span4">Despatch Date</div>
            <div class="span8">
                <input type="text" class="input-block-level" value="@(!string.IsNullOrEmpty(brief.DespatchDate.ToString()) ? brief.DespatchDate.ToString() : "N/A")" disabled="disabled" />
            </div>
        </div>
    </div>
    <form action="/rdm/addrdm" method="POST" id="frsavedispute" class="validaterdm">
        <input type="hidden" name="DisputeStatusID" id="hfDisputeStatusID" value="4" />
        <input type="hidden" name="QuestionnaireID" value="@Model.ID" />
        <input type="hidden" name="OrderItemID" value="@Model.OrderItemID" />
        <div class="row-fluid">
            <fieldset class="span6">
                <legend>RDM</legend>
                <div class="row-fluid">
                    <div class="span2">RDM Reason</div>
                    <div class="span4">
                        @Html.DropDownList("ReasonID", null, new { @class = "input-block-level", required = "required" })
                    </div>
                    <div class="span2">Reason Detail</div>
                    <div class="span4">
                        @Html.DropDownList("ReasonDetailID", null, new { @class = "input-block-level", required = "required" })
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">Liability</div>
                    <div class="span4">
                        @Html.DropDownList("LiabilityID", null, new { @class = "input-block-level", required = "required" })
                    </div>
                    <div class="span2">Preferred Resolution</div>
                    <div class="span4">
                        @Html.DropDownList("ResolutionID", null, "Please Select a Resolution", new { @class = "input-block-level", required = "required", onchange = "resolutionchange(this.value)" })
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">Crime Reference Number</div>
                    <div class="span10">
                        <input type="number" name="CrimeReferenceNumber" class="input-block-level" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">RDM Items</div>
                    <div class="span8">
                        <textarea class="input-block-level" rows="2" name="DisputeItems" id="DisputeItems">
@*@(Model.Order_Items + Environment.NewLine + orderItem.ProductSubOptions)*@
</textarea>
                        <input type="hidden" id="hfDisputeItems" value="@(Model.Order_Items + Environment.NewLine + orderItem.ProductSubOptions)"/>
                    </div>
                    <div class="span2">
                        <input type="checkbox" style="float: left; margin-right: 7px;" name="IsFullDisputeItems" id="IsFullDisputeItems" value="True" />
                        Full Item
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">Replacement Items</div>
                    <div class="span8">
                        <textarea class="input-block-level" rows="2" name="DisputeReplacementItems" id="DisputeReplacementItems">
@*@(Model.Order_Items + Environment.NewLine + orderItem.ProductSubOptions)*@
</textarea>
                        <input type="hidden" id="hfDisputeReplacementItems" value="@(Model.Order_Items + Environment.NewLine + orderItem.ProductSubOptions)" />
                    </div>
                    <div class="span2">
                        <input type="checkbox" style="float: left; margin-right: 7px;" name="IsFulDisputeReplacementItems" value="True" id="IsFulDisputeReplacementItems" />
                        Full Item
                    </div>
                </div>
                <div class="row-fluid" style="margin-bottom: 10px">
                    <div class="span2"></div>
                    <div class="span6">
                        <input type="checkbox" style="float: left; margin-right: 7px;" value="True" name="Urgent" />
                        Mark as Urgent
                    </div>
                    <div class="span4">
                        <a href="/rdm/@(Model.IsFAC51CheckList == true ? "viewquestionnaireform" : "viewquestionnairenonfac")?qid=@Model.ID" class="btn btn-primary">View Questionnaire</a>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">Full Description</div>
                    <div class="span10">
                        <textarea class="input-block-level" rows="3" name="Description"> @futherDescription  </textarea>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">Signature</div>
                    <div class="span10">
                        @Html.DropDownList("SignatureID", null, "Please Select a Singature", new { @class = "input-block-level", required = "required" })
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">Packaging</div>
                    <div class="span10">
                        @Html.DropDownList("PackagingID", null, "Please Select a Packaging Description", new { @class = "input-block-level", required = "required" })
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">Consignment No.</div>
                    <div class="span10">
                        <input type="text" class="input-block-level" name="ConsignmentNumber" />
                    </div>
                </div>
            </fieldset>

            <div class="span6">
                <ul class="tabs tabs-inline tabs-top orderdetail-task-tabs">
                    <li class="active">
                        <a href="#Photos" data-toggle="tab">Photos</a>
                    </li>
                    <li>
                        <a href="#Evidence" data-toggle="tab">Other Evidence</a>
                    </li>
                    <li>
                        <a href="#ItemPart" data-toggle="tab" onclick="RdmOrderItemPartDetail(@Model.OrderItemID,0,$('#ItemPart'))">Order Item Part</a>
                    </li>
                </ul>

                <div class="tab-content padding tab-content-inline tab-content-bottom orderdetail-task-tabs-content">
                    <div class="tab-pane active" id="Photos">
                        <div class="rdm-tab-scroll" style="height: 306px">
                            <div class="tbl-photodispute">
                                @Html.Action("PhotosDispute")
                            </div>
                        </div>
                        <p class="text-right"><a href="#addPhoto" role="button" data-toggle="modal" class="btn btn-primary">Add photo</a></p>
                    </div>
                    <div class="tab-pane" id="Evidence">
                        <div class="rdm-tab-scroll" style="height: 306px">
                            <div class="tbl-documentdispute">
                                @Html.Action("DocumentDispute")
                            </div>
                        </div>
                        <p class="text-right"><a href="#addDocument" role="button" data-toggle="modal" class="btn btn-primary">Add document</a></p>
                    </div>
                    <div class="tab-pane" id="ItemPart"></div>
                </div>

                <div class="border-padding10 text-right">
                    <div class="row-fluid">
                        <div class="span3"></div>
                        <div class="span4">Preferred Collection Date</div>
                        <div class="span4">
                            <div id="datetimepicker2" class="input-append">
                                <input data-format="dd/MM/yyyy HH:mm:ss" type="text" name="PreferredCollectionDate" id="PreferredCollectionDate" value="@DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")" />
                                <span class="add-on">
                                    <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span2"></div>
                        <div class="span4">
                            Collection Fee Required
                            <input type="checkbox" style="float: right; margin-left: 10px;" value="True" name="CollectionFeeRequired" />
                        </div>
                        <div class="span3">Collection Fee(£)</div>
                        <div class="span3">
                            <input type="text" class="input-block-level" name="CollectionFee" value="0.00" />
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div class="border-padding10 text-right" style="margin: 0">
            <button class="btn btn-primary" style="margin-right: 10px" onclick="javascript:window.close();">Cancel</button>
            @*<button class="btn btn-primary" style="margin-right: 10px" type="button" id="saverdm">Save</button>*@
            <button class="btn btn-primary" type="button" id="sendapproval">Send for Approval</button>
        </div>
    </form>
</div>
